#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, int> m;
        vector<int> ret;
        for(int i = 0; i < nums.size(); i++)
        {
            auto it = m.find(target - nums[i]);
            if(it != m.end())
            {
                ret.push_back(it->second);
                ret.push_back(i);
                break;
            }
            else
            {
                m.insert({nums[i],i});
            }
        }
        return ret;
    }
};

int main(void)
{
    vector<int> list = {2, 7, 11, 15};
    int target = 9;
    Solution s;
    vector<int> result;
    result = s.twoSum(list, target);

    for(auto n:result)
    {
        cout << n << " ";
    }
    cout << endl;
    return 0;
}
